<?php

declare(strict_types=1);

namespace app\shop\controller\api;

use think\Request;
use think\facade\Db;
use app\shop\model\Share as ShareModel;

class Share extends ShopBase
{

    public function add(Request $request)
    {
        $params = $request->only(['shareId', 'spm', 'page', 'query', 'from', 'platform']);

        $user = $this->auth()->user();

        $shareInfo = ShareModel::log($user, $params);

        return success("");
        // return success("", $shareInfo);
    }

    /**
     * 查看分享记录
     */
    public function list(Request $request)
    {
        $user = $this->auth()->user();
        $logs = ShareModel::with(['user' => function ($query) {
            return $query->field(['id', 'nickname', 'avatar']);
        }])->where('share_id', $user->id)->paginate($request->param('list_rows', 8));

        return success('获取成功', $logs);
    }
}
